package test;

//抽象动物类
abstract class Animal {
 private String name;
 private String species;
 private String breed;
 private double price;

 public Animal(String name, String species, String breed, double price) {
     this.name = name;
     this.species = species;
     this.breed = breed;
     this.price = price;
 }

 // 抽象方法，不同动物有不同的叫声
 public abstract void makeSound();

 // 吃饭方法
 public void eat() {
     System.out.println(name + " is eating.");
 }

 // 睡觉方法
 public void sleep() {
     System.out.println(name + " is sleeping.");
 }

 // 玩方法
 public void play() {
     System.out.println(name + " is playing.");
 }

 // 获取名字的方法
 public String getName() {
     return name;
 }

 // 获取种类的方法
 public String getSpecies() {
     return species;    }

 // 获取品种的方法
 public String getBreed() {
     return breed;
 }

 // 获取价格的方法
 public double getPrice() {
     return price;
 }
}

//猫类，继承自动物类
class Cat extends Animal {
 public Cat(String name, String species, String breed, double price) {
     super(name, species, breed, price);
 }

 @Override
 public void makeSound() {
     System.out.println("Meow!");
 }

 // 重写玩的方法，猫只有玩的时候才会叫
 @Override
 public void play() {
     super.play();
     makeSound();
 }
}

//狗类，继承自动物类
class Dog extends Animal {
 public Dog(String name, String species, String breed, double price) {
     super(name, species, breed, price);
 }

 @Override
 public void makeSound() {
     System.out.println("Woof!");
 }
}

//测试类
public class test {
 public static void main(String[] args) {
     // 实例化两只猫
     Cat cat1 = new Cat("Kitty", "Cat", "Persian", 500.0);
     Cat cat2 = new Cat("Mimi", "Cat", "Siamese", 400.0);

     // 实例化两只狗
     Dog dog1 = new Dog("Buddy", "Dog", "Golden Retriever", 800.0);
     Dog dog2 = new Dog("Max", "Dog", "German Shepherd", 900.0);

     // 测试猫的方法
     System.out.println("Cat 1:");
     cat1.eat();
     cat1.sleep();
     cat1.play();

     System.out.println("\nCat 2:");
     cat2.eat();
     cat2.sleep();
     cat2.play();

     // 测试狗的方法
     System.out.println("\nDog 1:");
     dog1.eat();
     dog1.sleep();
     dog1.play();

     System.out.println("\nDog 2:");
     dog2.eat();
     dog2.sleep();
     dog2.play();
 }
}